﻿using Liang.DataBase.Model.Entity;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;

namespace Liang.DataBase.Mapping.MySql
{
    public class OrganMap : EntityTypeConfiguration<sys_organ>
    {
        public OrganMap()
        {
            // 表名
            this.ToTable("sys_organ");

            // 主键
            this.HasKey(t => t.organId);

            // 属性设置
            this.Property(t => t.organId)
                .HasColumnName("organId")
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.Property(t => t.name)
                .HasColumnName("name")
                .HasMaxLength(120)
                .IsRequired();

            this.Property(t => t.phone)
                .HasColumnName("phone")
                .HasMaxLength(20);

            this.Property(t => t.address)
                .HasColumnName("address")
                .HasMaxLength(120);

            this.Property(t => t.basicdataId)
                .HasColumnName("basicdataId");

            // 关联设置
            this.HasRequired(t => t.basicdata)
                .WithMany()
                .HasForeignKey(t => t.basicdataId)
                .WillCascadeOnDelete(false);
        }
    }
}
